
<template>
  <div class="cart-item" @touchstart='touchStart' @touchend='touchEnd' @touchmove='touchmove'>
    <CheckButton :is-checked='itemInfo.check' @click.native='colorClick(itemInfo)' />
    <div class="item-img">
      <img :src="itemInfo.imgURL" alt="">
    </div>
    <div class="item-info">
      <p class="item-title">{{itemInfo.title}}</p>
      <p class="item-desc">商品描述:{{itemInfo.desc}}</p>
      <div class="item-bottom">
        <span class="item-price">￥{{itemInfo.newPrice}}</span>
        <span class="item-count">X {{itemInfo.count}}</span>
      </div>
    </div>
    <div class="mask" @click="closeBgc" v-show='isShowMask'>
      <div>
        <p>移入</p>
        <p>关注</p>
      </div>
      <div>
        <p>查看</p>
        <p>详情</p>
      </div>
      <div>相似</div>
      <div @click="remove(itemInfo)">删除</div>
    </div>
  </div>
</template>

<script>
import CheckButton from 'components/content/cartcheck/cartbuttonbar'
export default {
  components: { CheckButton },
  props: {
    itemInfo: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      id: '',
      timer: null,
      num: 0,
      isShowMask: false
    }
  },
  beforeDestroy() {
    clearInterval(this.timer)
  },
  methods: {
    colorClick(item) {
      this.$store.commit('editCartCheck', item.iid)
      // this.itemInfo.check = !this.itemInfo.check
    },
    touchStart() {
      this.timer = setInterval(() => {
        this.num++
        if (this.num > 1 && !this.isTop) {
          this.isShowMask = true
        }
      }, 500)
    },

    touchEnd() {
      clearInterval(this.timer)
      if (this.num > 1) {
        this.num = 0
      }
    },
    touchmove() {},
    closeBgc() {
      this.isShowMask = false
    },
    remove(item) {
      this.$store.dispatch('removeCar', item).then(res => {
        this.$toast.show(res)
      })
    }
  }
}
</script>

<style scoped>
.cart-item {
  position: relative;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 120px;
  padding: 0 2px;
  display: flex;

  align-items: center;
  border-bottom: 1px solid #eee;
}
.item-img {
  padding: 5px;
}
.item-img img {
  width: 75px;
  height: 100px;
}
.item-info {
  padding: 5px 1px;
  height: 100%;
  overflow: hidden;
}
.item-desc,
.item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-title {
  font-size: 17px;
  color: #333;
}
.item-desc {
  font-size: 14px;
  color: #666;
  margin-top: 20px;
}
.item-bottom {
  margin-top: 20px;
  padding: 0 2px;
  display: flex;
  justify-content: space-between;
}
.item-price {
  color: orangered;
}
.mask {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  background-color: rgba(0, 0, 0, 0.5);
  color: #fff;
}
.mask p {
  margin-top: 5px;
}
.mask > div {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 70px;
  height: 70px;
  background-color: orangered;
  text-align: center;
  border-radius: 50%;
}
.mask > div:nth-child(2) {
  background-color: orange;
}
.mask > div:nth-child(3) {
  background-color: palevioletred;
}
.mask > div:nth-child(4) {
  background-color: purple;
}
</style>
